package cn.edu.hitwh.kanlema.listener;

import cn.edu.hitwh.kanlema.constant.MqConstants;
import cn.edu.hitwh.kanlema.message.VoucherOrderMessage;
import cn.edu.hitwh.kanlema.service.IVoucherOrderService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderListener {
    @Autowired
    private IVoucherOrderService voucherOrderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.ORDER_VOUCHER_CREATE_QUEUE, durable = "true"),
            exchange = @Exchange(name = MqConstants.ORDER_EXCHANGE),
            key = MqConstants.ORDER_VOUCHER_KEY
    ))
    public void createVoucherOrder(VoucherOrderMessage message) {
        voucherOrderService.createVoucherOrder(message);
    }
}
